/**
 * 
 */
package com.google.code.maven.plugin.http.client;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.net.URLCodec;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

/**
 * RequestParameter
 * 
 * @author Nadim Benabdenbi
 * @version 1.0
 * @since JDK1.6
 */
public class RequestParameter {

	/**
	 * @parameter
	 * @required
	 */
	private String name;

	/**
	 * @parameter defaul-value=""
	 */
	private String value = "";

	/**
	 * url codec
	 */
	private final URLCodec codec = new URLCodec();

	/**
	 * 
	 */
	public RequestParameter() {
		super();
	}

	/**
	 * name getter.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 * @param value
	 */
	public RequestParameter(String name, String value) {
		super();
		this.name = name;
		this.value = value;
	}

	/**
	 * name setter.
	 * 
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * value getter.
	 * 
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * value setter.
	 * 
	 * @param value the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @param beanResolver
	 * @return
	 */
	public NameValuePair toNameValuePair() {
		return new BasicNameValuePair(name, value);
	}

	/**
	 * @param beanResolver
	 * @return
	 * @throws EncoderException
	 */
	public String toUrlParameter() throws EncoderException {
		return new StringBuilder(codec.encode(name)).append("=")//
				.append(codec.encode(value)).toString();
	}

	@Override
	public String toString() {
		return new StringBuilder(name).append("=").append(value).toString();
	}
}
